Find the maximum occurring characterΒΆ
Find the maximum occurring character in a given string.
def get_max_occuring_char(S):
ASCII_SIZE = 256
ctr = [0] * ASCII_SIZE
max = -1
ch = ''
for c in S:
ctr[ord(c)] += 1;
for c in S:
if max < ctr[ord(c)]:
max = ctr[ord(c)]
ch = c
return ch
# test
print(get_max_occuring_char("Python: \
Get file creation and modification date/times")) # t
print(get_max_occuring_char("abcdefghijkb")) # b